<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="开奖号码" prop="kjNum">
        <el-input
            v-model="queryParams.kjNum"
            placeholder="请输入开奖号码"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['system:history:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:history:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:history:remove']"
        >删除
        </el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="handleExport"-->
      <!--          v-hasPermi="['system:history:export']"-->
      <!--        >导出</el-button>-->
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="getAllHistory"
        >获取历史开奖
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="stat1"
        >统计1
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="stat2"
        >统计2
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleYcAdd"
        >获取预测号码
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="historyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="日期" align="center" prop="qs"/>
      <el-table-column label="开奖号码" align="center" prop="kjNum"/>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />
    <!-- 添加或修改排列5历史开奖对话框 -->
    <el-dialog :title="title" :visible.sync="ycOpen" width="800px" append-to-body>
      <el-form ref="form" :model="form2" :rules="rules" label-width="120px">
        <el-form-item label="预测期数" prop="qs">
          <el-col :span="10" class="card-box">
            <el-date-picker
                v-model="form2.qs"
                type="date"
                format="yyyyMMdd"
                value-format="yyyyMMdd"
                placeholder="选择日期">
            </el-date-picker>
          </el-col>

        </el-form-item>
        <el-form-item label="算    法">
          <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选
          </el-checkbox>
          <div style="margin: 15px 0;"></div>
          <el-checkbox-group v-model="form2.checkedCities" @change="handleCheckedCitiesChange">
            <el-checkbox v-for="city in cities" :label="city" :key="city">{{ city }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="算法号码个数" prop="ct">
          <el-input-number type="num" :min="1" :max="10" v-model="form2.ct"/>
        </el-form-item>
        <el-form-item label="冷热号码个数" prop="lrct">
          <el-input-number type="num" :min="1" :max="10" v-model="form2.lrct"/>
        </el-form-item>
        <el-form-item label="预测号码" prop="ycKjNum0">
          <el-row>
            <el-col :span="8">
              位置0
            </el-col><el-col :span="8">
            位置1
            </el-col><el-col :span="8">
            位置2
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-input readonly v-model="form2.ycKjNum0"/>
              <el-input readonly v-model="form2.rr0"/>
              <el-input readonly v-model="form2.ll0"/>
            </el-col>
            <el-col :span="8">
              <el-input readonly v-model="form2.ycKjNum1"/>
              <el-input readonly v-model="form2.rr1"/>
              <el-input readonly v-model="form2.ll1"/>
            </el-col>
            <el-col :span="8">
              <el-input readonly v-model="form2.ycKjNum2"/>
              <el-input readonly v-model="form2.rr2"/>
              <el-input readonly v-model="form2.ll2"/>
            </el-col>
          </el-row>
        </el-form-item>

        <el-form-item label="最终预测号码" prop="zzp0">
          <el-row>
            <el-col :span="8"><el-input readonly v-model="form2.zzp0"/> </el-col>
            <el-col :span="8"><el-input readonly v-model="form2.zzp1"/></el-col>
            <el-col :span="8"><el-input readonly v-model="form2.zzp2"/></el-col>
          </el-row>
        </el-form-item>

        <el-form-item label="实际开奖号码" prop="sjkjNum">
          <el-col :span="6"><el-input readonly v-model="form2.sjkjNum"/></el-col>
          <el-col :span="2">
            <el-button v-if="this.form2.sfzj !== '未中奖' " type="success" icon="el-icon-success" circle></el-button>
            <el-button v-else type="danger" icon="el-icon-error" circle></el-button>
          </el-col>
          <el-col :span="2">
            投入
          </el-col>
          <el-col :span="6">
            <el-input readonly v-model="form2.tr"/>
          </el-col>
          <el-col :span="2">
            利润
          </el-col>
          <el-col :span="6" v-if="this.form2.sfzj != '未中奖' ">
            <el-input readonly v-model="form2.lr"/>
          </el-col>
        </el-form-item>
        <el-form-item label="间隔几几期" prop="jgCount">
          <el-input-number type="num" :min="0" :max="3" v-model="form2.jgCount"/>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="changeQs">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  addHistory,
  delHistory,
  getAllHistory,
  getHistory,
  getYcKjNum,
  listHistory,
  stat1,
  stat2,
  updateHistory
} from "@/api/caipiao/historypl5.js";

const cityOptions = ['和值', '和值奇偶', '和值012路', '和值质合属性',
  '跨度值', '跨度奇偶', '跨度012路', '跨度质合属性',
  '各号码', '各号码奇偶', '各号码012路', '各号码质合属性'];
export default {
  name: "History",
  data() {
    return {
      checkAll: false,
      cities: cityOptions,
      isIndeterminate: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 排列5历史开奖表格数据
      historyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      ycOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        kjNum: ''
      },
      // 表单参数
      form: {},
      form2: {
        qs: '',//Vue.prototype.formatDateYYYYMMDD(new Date()),
        ycKjNum0: '',
        ycKjNum1: '',
        ycKjNum2: '',
        ct: 4,
        lrct: 3,
        sjkjNum: '',
        checkedCities: ['和值'],
        lr: 0,
        sfzj: '',
        rr0: '',
        rr1: '',
        rr2: '',
        ll0: '',
        ll1: '',
        ll2: '',
        zzp0: '',
        zzp1: '',
        zzp2: '',
        tr: 0,
        jgCount: 0,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleCheckAllChange(val) {
      this.form2.checkedCities = val ? cityOptions : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length;
    },
    /** 查询排列5历史开奖列表 */
    getList() {
      this.queryParams.pageNum = 1;
      this.queryParams.orderByColumn = "qs"
      this.queryParams.isAsc = "desc"
      this.loading = true
      listHistory(this.queryParams).then(response => {
        this.historyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        qs: null,
        kjNum: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.orderByColumn = "qs"
      this.queryParams.isAsc = "desc"
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.qs)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加排列5历史开奖";
    },
    /** 打开预测窗口按钮操作 */
    handleYcAdd() {
      this.reset();
      this.ycOpen = true;
      this.title = "预测排列3";

      // this.changeQs()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const qs = row.qs || this.ids
      getHistory(qs).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改排列5历史开奖";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.qs != null) {
            updateHistory(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHistory(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const qss = row.qs || this.ids;
      this.$modal.confirm('是否确认删除排列5历史开奖编号为"' + qss + '"的数据项？').then(function () {
        return delHistory(qss);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/history/export', {
        ...this.queryParams
      }, `history_${new Date().getTime()}.xlsx`)
    },
    /** 获取历史开奖操作 */
    getAllHistory() {
      getAllHistory().then(response => {
        this.$modal.msgSuccess("操作成功");
        this.open = false;
        this.getList();
      });
    },
    /** 统计1 */
    stat1() {
      stat1().then(response => {
        this.$modal.msgSuccess("操作成功");
        this.open = false;
        // this.getList();
      });
    },
    /** 统计2 */
    stat2() {
      stat2().then(response => {
        this.$modal.msgSuccess("操作成功");
        this.open = false;
        // this.getList();
      });
    },
    changeQs() {
      if (!this.form2.qs) {
        this.$modal.alertError("请选择预测期数")
        return
      }
      if (!this.form2.checkedCities || this.form2.checkedCities.length == 0) {
        this.$modal.alertError("请选择算法")
        return
      }
      console.log("qs", this.form2.qs)
      this.form2.qs = this.form2.qs.replaceAll('-', '')
      getYcKjNum(this.form2).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.form2.ycKjNum0 = response.data.p0;
        this.form2.ycKjNum1 = response.data.p1;
        this.form2.ycKjNum2 = response.data.p2;
        this.form2.sjkjNum = response.data.sjkjNum;
        this.form2.lr = response.data.lr;
        this.form2.tr = response.data.tr;
        this.form2.sfzj = response.data.sfzj;

        this.form2.rr0 = "热：" + response.data.rr0;
        this.form2.rr1 = "热：" + response.data.rr1;
        this.form2.rr2 = "热：" + response.data.rr2;
        this.form2.ll0 = "冷：" + response.data.ll0;
        this.form2.ll1 = "冷：" + response.data.ll1;
        this.form2.ll2 = "冷：" + response.data.ll2;


        this.form2.zzp0 = response.data.zzp0;
        this.form2.zzp1 = response.data.zzp1;
        this.form2.zzp2 = response.data.zzp2;

      })
    }
  }
};
</script>
